Deleting the first occurrence of a target in aList [closed]

Posted by Bandz Jooz on Stack Overflow See other posts from Stack Overflow or by Bandz Jooz
Published on 2012-09-22T03:16:33Z Indexed on 2012/09/22 3:37 UTC
Read the original article Hit count: 86

Filed under:
|
|
|
|
/** Replaces each occurrence of oldItem in aList with newItem */
public static void replace(List<Student> aList, Student oldItemStudent newItem) {
    int index = aList.indexOf(oldItem);
    while(index != -1){
    aList.set(index, newItem);
    index = aList.indexOf(oldItem);
}
/** Deletes the first occurrence of target in aList */
public static void delete(List<Student> aList, Student target){
    Object o = //stuck here, dont know how to set up boolean stuff
 }
}

I figured out how to do the first method by looking up Java documentation, however I can't figure out how to finish my code for the second method even though I looked up the documentation which states:

boolean remove(Object o) Removes the first occurrence of the specified element from this list, if it is present.

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays